package com.coocaa.ops.api.base.third.media.source.feign;

import com.coocaa.ops.api.base.properties.HostProperties;
import feign.*;
import feign.codec.Decoder;
import feign.codec.Encoder;
import feign.hystrix.HystrixFeign;
import org.springframework.cloud.openfeign.FeignClientsConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * @author bijiahao
 * @date : 2019/7/1.
 * @description:
 *
 *     获取媒资策略的 Feign自定义配置
 *
 */
@Configuration
@Import(FeignClientsConfiguration.class)
public class GetPolicyFeignConfigure {
    private static final int CONNECT_TIMEOUT_MILLIS = 500;

    private static final int READ_TIMEOUT_MILLIS = 500;

    @Bean
    public GetPolicyFeignClient getPolicyFeignClient(Encoder encoder, Decoder decoder
            , Contract contract, Client client, GetPolicyFallBackFactory fallBackFactory
            , HostProperties properties) {
        return HystrixFeign.builder()
                .encoder(encoder)
                .decoder(decoder)
                .options(new Request.Options(CONNECT_TIMEOUT_MILLIS, READ_TIMEOUT_MILLIS))
                .retryer(new Retryer.Default())
                .logLevel(Logger.Level.FULL)
                .contract(contract)
                .client(client)
                .target(GetPolicyFeignClient.class, properties.getMedia(), fallBackFactory);
    }
}
